/**
 * BulkSMSAAASbb
 * 
 * This SBB receives HTTP requests from the predecessor and does some accounting
 */
package org.convergence.services.slee.bulksms.aaa;

import javax.slee.ActivityContextInterface;
import javax.slee.ChildRelation;
import javax.slee.CreateException;
import javax.slee.RolledBackContext;
import javax.slee.Sbb;
import javax.slee.SbbContext;
import javax.slee.SbbLocalObject;
import javax.slee.facilities.Tracer;

import org.mobicents.slee.SbbContextExt;

import net.java.slee.resource.http.events.HttpServletRequestEvent;

public abstract class BulkSMSAAASbb implements Sbb {
	private Tracer tracer;
	
	private String strTo;
	private String strText;
    
	public void onServiceStartedEvent(javax.slee.serviceactivity.ServiceStartedEvent event, ActivityContextInterface aci) {
		tracer.info("Bulk SMS AAA Service Started");
	}
	
	/*
	 * OnGet: process the GET operation from an external system
	 * in:
	 * 		HttpServletRequestEvent: the http type event from the RA
	 * 		ActivityContextInterface: the activity context associated with the event
	 */
	public void onGet(HttpServletRequestEvent event, AaaSbbActivityContextInterface aci) {
		tracer.info("Received GET operation");
		
		if(aci.getProcessedByPredecessor()) {
			tracer.info("Processed by Predecessor");
			aci.setProcessedByMe(true);
		}
		else {
			tracer.info("Not processed by Predecessor");
			aci.setProcessedByMe(false);
		}
		
		SbbLocalObject sbbLocalObject = sbbContext.getSbbLocalObject();
        aci.detach(sbbLocalObject);
	}
	
	/*
	 * (non-Javadoc)
	 * @see javax.slee.Sbb#setSbbContext(javax.slee.SbbContext)
	 * Beginning of the life cycle of the SBB
	 * 
	 * 		in:
	 * 				SbbContext - passed to the SBB by the SLEE so it can invoke SLEE facilities
	 */
	public void setSbbContext(SbbContext context) { 
		this.sbbContext = (SbbContextExt) context;
		tracer = sbbContext.getTracer(getClass().getSimpleName());
	}
	
	public void unsetSbbContext() { this.sbbContext = null; }

	// TODO: Implement the lifecycle methods if required
	public void sbbCreate() throws javax.slee.CreateException {}
	public void sbbPostCreate() throws javax.slee.CreateException {}
	public void sbbActivate() {}
	public void sbbPassivate() {}
	public void sbbRemove() {}
	public void sbbLoad() {}
	public void sbbStore() {}
	public void sbbExceptionThrown(Exception exception, Object event, ActivityContextInterface activity) {}
	public void sbbRolledBack(RolledBackContext context) {}
	
	public abstract org.convergence.services.slee.bulksms.aaa.AaaSbbActivityContextInterface asSbbActivityContextInterface(ActivityContextInterface aci);


	
	/**
	 * Convenience method to retrieve the SbbContext object stored in setSbbContext.
	 * 
	 * TODO: If your SBB doesn't require the SbbContext object you may remove this 
	 * method, the sbbContext variable and the variable assignment in setSbbContext().
	 *
	 * @return this SBB's SbbContext object
	 */
	
	protected SbbContextExt getSbbContext() {
		return sbbContext;
	}

	private SbbContextExt sbbContext; // This SBB's SbbContext
}
